/*
 * CommandComponentTag.java
 *
 * Created on May 21, 2007, 3:03 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.javatech.jmf.components.command.server;

import javax.faces.component.UIComponent;
import javax.faces.event.MethodExpressionActionListener;
import javax.faces.webapp.UIComponentELTag;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

/**
 *
 * @author root
 */
public class CommandComponentTag extends UIComponentELTag{
    
    private ValueExpression shortTitle;
    private ValueExpression longTitle;
    private ValueExpression priority;
    private ValueExpression type;
    
    private MethodExpression actionListener;
    private MethodExpression action;
    
    /** Creates a new instance of CommandComponentTag */
    public CommandComponentTag() {
    }
    
    public String getComponentType() {
        return "jmf.command";
    }
    
    public String getRendererType() {
        return null;
    }
    
    public void setShortTitle(ValueExpression shortTitle) {
        this.shortTitle = shortTitle;
    }
    
    public void setLongTitle(ValueExpression longTitle) {
        this.longTitle = longTitle;
    }
    
    public void setPriority(ValueExpression priority) {
        this.priority = priority;
    }
    
    public void setType(ValueExpression type) {
        this.type = type;
    }
    
    public void setActionListener(MethodExpression actionListener) {
        this.actionListener = actionListener;
    }
    
    public void setAction(MethodExpression action) {
        this.action = action;
    }
    
    protected void setProperties(UIComponent component) {
        super.setProperties(component);
        
        CommandComponent command = (CommandComponent) component;
        
        command.setValueExpression("shortTitle",shortTitle);
        command.setValueExpression("longTitle",longTitle);
        command.setValueExpression("priority",priority);
        command.setValueExpression("type",type);
        
        if (action!=null)
            command.setActionExpression(action);
        
        if (actionListener!=null)
            command.addActionListener(new MethodExpressionActionListener(actionListener));
    }
    
    public void release() {
        super.release();
        setShortTitle(null);
        setLongTitle(null);
        setPriority(null);
        setType(null);
        setAction(null);
        setActionListener(null);
    }
    
    
    
}
